﻿﻿<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="/wwwroot/bootstrap.min.css" />
    <link rel="stylesheet" href="/wwwroot/common/css/sapar.css?v=@FileServer.Common.VersionNo.VNo" />
    <link rel="stylesheet" href="/wwwroot/common/css/common.css?v=@FileServer.Common.VersionNo.VNo" />
    <script type="text/javascript" src="/wwwroot/common/js/jquery-1.12.4.js"></script>
    <title>云盘文件列表</title>
</head>
<body>
    <div class="container-fluid">
        <h2>云盘</h2>
        
        <div class="row">
            <div class="col-12">
                <div class="input-group mb-3">
                    <input type="text" id="name" class="form-control" placeholder="搜索文件夹/文件名称">
                    <button class="btn btn-primary" onclick="loadFileList()">查询</button>
                </div>
            </div>
        </div>

        <div class="row" id="file-list">
            <!-- 文件列表将在此处显示 -->
        </div>
    </div>

    <script>
        const parentGuid = new URLSearchParams(window.location.search).get('parentGuid') || '';
        const spaceType = new URLSearchParams(window.location.search).get('spaceType') || '';

        function loadFileList() {
            $.ajax({
                url: 'http://localhost:8060/api/file/getFileList',
                method: 'GET',
                data: {
                    parentGuid: parentGuid,
                    spaceType: spaceType
                },
                success: function(response) {
                    if (response && response.data) {
                        renderFileList(response.data);
                    }
                }
            });
        }

        function renderFileList(items) {
            var html = '';
            items.forEach(function(item) {
                html += `
                <div class="col-12 mb-2">
                    <div class="card">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h5>${item.name}</h5>
                                    <small>${item.create_time}</small>
                                </div>
                                <div>
                                    <button class="btn btn-sm btn-primary" onclick="handleFileClick('${item.guid}')">
                                        查看
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>`;
            });
            $('#file-list').html(html);
        }

        function handleFileClick(guid) {
            window.location.href = `list.html?parentGuid=${guid}&spaceType=${spaceType}`;
        }

        $(document).ready(function() {
            loadFileList();
        });
    </script>
</body>
</html>
